<template>
    <div>
     <h1>康复理疗添加功能</h1>
     <table>
        <tr>
            <td>名称</td>
            <td><input type="text" v-model="data.kname">
                <a v-if="!data.kname" style="color: red;">*</a>
            </td>
           
        </tr>
        <tr>
            <td>佣金</td>
            <td><input type="text" v-model="data.price">
                <a v-if="!data.price" style="color: red;">*</a>
            </td>
           
        </tr>
        <tr>
            <td>状态</td>
            <td><input type="checkbox" v-model="data.ksates">选中代表true</td>
        </tr>
        <tr>
            <td>服务人数</td>
            <td><input type="text" v-model="data.furen">
                <a v-if="!data.furen" style="color: red;">*</a>
            </td>
        </tr>
        <tr>
            <td>服务时长</td>
            <td><input type="text" v-model="data.fushi">
                <a v-if="!data.fushi" style="color: red;">*</a>
            </td>
        </tr>
        <tr>
            <td></td>
            <td><input type="button" value="提交" @click="Add"></td>
        </tr>
     </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { useRouter } from 'vue-router';
import { ref } from 'vue';

const router=useRouter();

const data=ref({
    
    "kid": 0,
  "kname": "",
  "price": "",
  "ksates": true,
  "furen": null,
  "fushi": null

})

const Add=()=>
{

if(data.value.kname=="")
{
    alert("康复标题不能为空");
    return;
}
if(data.value.price=="")
{
    alert("佣金不能为空");
    return;
}
if(data.value.furen==null)
{
    alert("服务人数不能为空");
    return;
}
if(data.value.furen*0!=0)
{
    alert("服务人数必须是整数");
    return;
}


if(data.value.fushi==null)
{
    alert("服务时长不能为空");
    return;
}
if(data.value.fushi*0!=0)
{
    alert("服务时长必须是整数");
    return;
}


    axios.post("https://localhost:7076/api/kang/Add",data.value).then(res=>
        {
            if(res.data>0)
        {
            alert("添加成功");
            router.push({path:"/App"});
        }
        else{
            alert("添加失败");
            return
        }
        }
    )
}

</script>

<style scoped>

</style>